package com.ruoyi.mp.api.factory;

import com.ruoyi.common.core.constant.SecurityConstants;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.mp.api.RemoteMpCodeFactoryService;
import com.ruoyi.mp.api.domain.MpGetCode;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;

/**
 * 文件服务降级处理
 * 
 * @author ruoyi
 */
@Component
public class RemoteMpCodeFactoryFactory implements FallbackFactory<RemoteMpCodeFactoryService>
{
    private static final Logger log = LoggerFactory.getLogger(RemoteMpCodeFactoryFactory.class);

    @Override
    public RemoteMpCodeFactoryService create(Throwable throwable)
    {
        log.error("文件服务调用失败:{}", throwable.getMessage());
        return new RemoteMpCodeFactoryService()
        {
            @Override
            public R<String> mpGetcodeUrl(@RequestBody MpGetCode mpGetCode, @RequestHeader(SecurityConstants.FROM_SOURCE) String source)
            {
                return R.fail("调用二维码失败:" + throwable.getMessage());
            }
        };
    }
}
